﻿var $ = (function(global){
    "use strict";
    var $D = document,
        $DB = document.body,
        $LS = window.localStorage,
        $W = window,
        $M = Math,
        $DE = $D.documentElement;

    var u = navigator.userAgent.toLowerCase(),
        isIE = (u.indexOf('msie') > 0),
        isFF = (u.indexOf('firefox') > 0),
        isPad = ("createTouch" in $D),
        bsVer = (u.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
        _fn = function () { };

    var $ = function (s) {
        if (s === '') {
            return $.getType();
        }
        if (!s) {
            return;
        }
        var t = typeof (s);
        if (t == 'function') {
            $.onReady(s);
        } else {
            return (t == 'string' ? (s.charAt(0) == '{' ? (eval('(' + s + ')')) : $.ext($D.getElementById(s), _x)) : $.ext(s, _x));
        }
    };

    var _s = {
        toLow: function() {
            return this.toLowerCase();
        },
        toUp: function() {
            return this.toUpperCase();
        },
        firstToUp: function() {
            return this.replace(/\b\w+\b/g, function(w) {
                return w.substring(0, 1).toUpperCase() + w.substring(1);
            });
        },
        cn2css: function() {
            var a = this.replace(/\s{2,}/g, ' ').split(" "),
                cssAry = [];
            for (var i = 0; i < a.length; i++) cssAry[i] = $.skin.classObj[a[i]];
            return cssAry.join(';') + ';';
        },
        esHtml: function() {
            return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
        },
        toHtml: function() {
            return this.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
        },
        reHtml: function() {
            return this.replace(/<\/?[^>]+>/gi, '');
        },
        times: function(n) {
            return n ? new Array(n + 1).join(this) : '';
        },
        parseHtml: function(a) {
            var _ss = this.toString().split('<script');
            $(a).h(_ss.shift());
            for (var i = 0, _len = _ss.length; i < _len; i++) {
                if (_ss[i].indexOf('src') != -1) {
                    var _attrAry = _ss[i].trim().match(/([^\x00]+)\><\/script>$/i)[1].split(' ')
                    for (var idx = 0; idx < _attrAry.length; idx++) {
                        var _kv = _attrAry[idx].split('=');
                        if (_kv[0] == 'src') {
                            _load.loadjs(_kv[1].replaceAll('"', '').trim());
                        }
                    }
                } else {
                    if (_ss[i] && ('<script' + _ss[i]).match(/<script[^>]*>([^\x00]+)<\/script>$/i)) {
                        eval(('<script' + _ss[i]).match(/<script[^>]*>([^\x00]+)<\/script>$/i)[1].trim());
                    }
                }
            }
        },
        format: function() {
            var s = this,
                a = [];
            for (var i = 0, l = arguments.length; i < l; i++) a.push(arguments[i]);
            return s.replace(/\{(\d+)\}/g, function(m, i) {
                return a[i]
            });
        },
        len: function() {
            return this.replace(/[^\x00-\xff]/g, '**').length;
        },
        toInt: function() {
            return parseInt(this, 10);
        },
        toElm: function(s) {
            var o = $(s);
            o.h(this);
            return o;
        },
        isDate: function() {
            var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
            if (r == null) return false;
            var d = new Date(r[1], r[3] - 1, r[4]);
            return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4]);
        },
        isTime: function() {
            var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
            if (r == null) return false;
            var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
            return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
        },
        replaceAll: function(s1, s2) {
            var a = this.split(s1);
            return a.join(s2);
        },
        test: function(r) {
            return r.test(this);
        },
        trim: function() {
            return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        },
        camelize: function() {
            return this.replace(/(-[a-z])/g, function(s) {
                return s.substring(1).toUpperCase();
            });
        },
        ec: function(s) {
            return (new RegExp('(^' + s + '\\s)|(\\s' + s + '$)|(\\s' + s + '\\s)|(^' + s + '$)', 'g')).test(this);
        },
        tc: function(s) {
            if (this.ec(s)) {
                return this.dc(s);
            } else {
                return this.ac(s);
            }
        },
        dc: function(s) {
            if (this.ec(s)) {
                return this.replace(new RegExp('(^' + s + '\\s)|(\\s' + s + '$)|(\\s' + s + '\\s)|(^' + s + '$)', 'g'), '').replace(/\s{2,}/g, ' ');
            } else{
                return this;
            }
        },
        ac: function(s) {
            return this.dc(s) + ' ' + s;
        }
    }; //---end---string

    var _a = {
        max: function() {
            return $M.max.apply({}, this);
        },
        min: function() {
            return $M.min.apply({}, this);
        },
        copy: function() {
            return [].concat(this);
        },
        clear: function() {
            return this.length = 0, this;
        },
        re: function(v) {
            while (true) {
                var n = this.idxOf(v);
                if (n >= 0){
                    this.reAt(n);
                }else {
                    return this;
                }
            }
        },
        reAt: function(n) {
            return this.splice(n, 1), this;
        },
        unique: function(w) {
            var _a = {};
            this.ec(function(i) {
                if (!w || (w && this[i])) {
                    _a[this[i]] = true;
                }
            });

            this.length = 0;
            for (var i in _a) {
                if (_a.hasOwnProperty(i)) {
                    this[this.length] = i;
                }
            }

            return this;
        },
        combine: function() {
            return [].concat.apply(this, arguments).unique();
        },
        ec: function(fn, context) {
            for (var i = 0, l = this.length; i < l;i++) {
                fn.call(context || this, i, this[i]);
            }

            return this;
        },
        filter: function(fn) {
            var a = [];
            this.ec(function(i) {
                if (fn(this[i])) {
                    a.push(this[i]);
                }
            });
            return a;
        },
        idxOf: function(v) {
            var me = this;
            if ([].indexOf) {
                return me.indexOf(v);
            } else {
                for (var i = 0, l = me.length; i < l; i++) {
                    if (me[i] === v) {
                        return i;
                    }
                }
                return -1;
            }
        }
    };//---end---array

    var _d = {
        date8: function(s) {
            var m = this.getMonth() + 1,
                d = this.getDate(),
                m = m <= 9 ? ("0" + m) : m,
                d = d <= 9 ? ("0" + d) : d,
                s = s || '';

            return [this.getFullYear(), m, d].join(s);
        },
        date2Str: function() {
            return (this.getFullYear() + '-' + (this.getMonth() + 1) + '-' + this.getDate() + ' ' + this.getHours() + ':' + this.getMinutes() + ':' + this.getSeconds());
        },
        str2Date: function(str) {
            if (!str) {
                return false;
            };
            var a = str.match(/[0-9]+/g);
            this.setFullYear($.m.p(a[0] || 1900), $.m.p(a[1] || 1) - 1, $.m.p(a[2] || 1));
            this.setHours($.m.p(a[3] || 0));
            this.setMinutes($.m.p(a[4] || 0));
            this.setSeconds($.m.p(a[5] || 0));
            return this;
        },
        format: function(format) {
            //{ M+: month, d+: day, h+: hour, m+: minute, q+: quarter, S: millisecond }
            var o = {
                "M+": this.getMonth() + 1,
                "d+": this.getDate(),
                "h+": this.getHours(),
                "m+": this.getMinutes(),
                "s+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3),
                "S": this.getMilliseconds()
            };
            if (/(y+)/.test(format)) {
                format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(format)) {
                    format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
                };
            }
            return format;
        }
    };//---end---date

    var _f = {
        help: function(s, e) {
            var l = "" + this;
            var s = s || "/*",
                e = e || "*/";
            l = l.substring(l.indexOf(s) + 3, l.lastIndexOf(e));
            return l.trim();
        }
    };//---end---function

    var _x = {
        alpha: function(a) {
            if (a || a == '') {
                if (isIE && +bsVer < 10) {
                    this.alp = a / 100;
                    $S(this).filter = 'alpha(opacity=' + a + ')'
                } else {
                    $S(this).opacity = a / 100;
                }
                return this;
            } else {
                if (isIE) {
                    if ($S(this).filter == '') {
                        return 0;
                    }
                    return $.m.p(this.filters.alpha.opacity);
                } else {
                    if ($S(this).opacity == '') {
                        return 0;
                    }
                    return $.m.p($S(this).opacity * 100);
                }
            };
        },
        ease: function(propArray, endProp, during, type, backFun, ifQ, ifPx) {
            var ifPx = ifPx || "px";
            if (ifPx == "") {
                ifPx = 0;
            };
            type = (type == 1 || (_tween[type] === undefined)) ? 'easeNone' : type;
            var me = this,
                dt = [],
                pAry = [],
                bAry = [],
                eAry = [],
                sAry = [],
                l = propArray.length;
            for (var i = 0; i < l; i++) {
                pAry.push(propArray[i].camelize());
                eAry.push(endProp[i]);
                var _s = $S(me)[pAry[i]] || "0";
                if (pAry[i] == 'alpha') {
                    _s = me.alpha()
                };
                _s = $.m.p(_s);
                sAry.push(_s);
                dt.push(eAry[i] - _s);
                bAry.push(_s);
            };
            var n = 0;
            var step = 16;
            var time = setTimeout(anitime, step);
            timeIntervalArray.push(time);

            function anitime() {
                var tAdjust = during - step;
                var t = n / tAdjust;
                n += 2 * step;
                if (n >= during) {
                    for (var k = 0; k < l; k++) {
                        if (pAry[k] == 'alpha') {
                            me.alpha(eAry[k])
                        } else {
                            $S(me)[pAry[k]] = eAry[k] + ifPx
                        };
                    };
                    var fun = backFun.e || '';
                    if (typeof(fun) == 'string') {
                        eval(fun)
                    } else {
                        fun()
                    };
                    clearTimeout(time);
                    return
                };
                for (var i = 0; i < l; i++) {
                    sAry[i] = _tween[type](n, bAry[i], dt[i], during);
                    if (pAry[i] == 'alpha') {
                        me.alpha(sAry[i]);
                    } else {
                        $S(me)[pAry[i]] = $M.ceil(sAry[i]) + ifPx;
                    }
                }
                var t = setTimeout(anitime, step);
                var ff = backFun.f || '';
                if (typeof(ff) == 'string') {
                    eval(ff);
                } else {
                    ff();
                }
            };
            return this;
        },
        animate: function(a) {

        },
        load: function(o, f, a) {
            var _u = o,
                _m = this,
                _f = f || _fn ||
                    function() {};
            if (!_u) {
                return _m;
            };
            switch ($.getType(_u)) {
                case 'object':
                    _u.p = _m;
                    _u.onload = _f;
                    new $.UI.View(_u);
                    break;
                case 'string':
                    var _suffix = (/\.[^\.]+$/.exec(_u)[0]).toLowerCase();
                    if (_suffix == '.js') {
                        var _a = {
                            p: _m,
                            url: _u,
                            onLoad: _f
                        };
                        new $.UI.View($.init(_a, (a || {})));
                    } else {
                        $.ajax({
                            url: _u,
                            dataType: 'html',
                            onSuccess: function(rt) {
                                rt.toString().parseHtml(_m);
                                _f(rt);
                            }
                        });
                    };
                    break;
            }
            return _m;
        },
        adElm: function(a, b) {
            var e = $C(a, b);
            this.appendChild(e);
            return $(e);
        },
        //可解决先$C再innerHTML的内存泄露问题
        appendTo: function(o) {
            o.appendChild(this);
            return this;
        },
        scrollTo: function(a) {
            var _args = $.init(a, {
                    onScroll: _fn,
                    onComplete: _fn
                }),
                _kv = {
                    'left': 'scrollLeft',
                    'top': 'scrollTop',
                    'width': 'scrollWidth',
                    'height': 'scrollHeight'
                },
                _self = this,
                _k;
            for (var i in _args) {
                if ($.getType(_args[i]) == 'function') {
                    continue;
                };
                _k = _kv[i.toLowerCase()];
                $.animate({
                    begin: _self[_k],
                    end: _args[i],
                    step: 16,
                    easing: 'easeNone',
                    interval: 500,
                    onComplete: _args.onComplete,
                    onRunning: function(obj) {
                        _self[_k] = obj.value;
                        _args.onScroll(obj);
                    }
                });
            };
            return _self;
        },
        bbElm: function(a, b) {
            var e = $C(a, b);
            this.insertAdjacentElement("beforeBegin", e);
            return $(e);
        },
        abElm: function(a, b) {
            var e = $C(a, b);
            this.insertAdjacentElement("afterBegin", e);
            return $(e);
        },
        aeElm: function(a, b) {
            var e = $C(a, b);
            this.insertAdjacentElement("afterEnd", e);
            return $(e);
        },
        beElm: function(a, b) {
            var e = $C(a, b);
            this.insertAdjacentElement("beforeEnd", e);
            return $(e);
        },
        attr: function(a, s) {
            if (a == undefined) {
                return this;
            };
            if (arguments.length == 1) {
                return this.getAttribute(a);
            } else {
                if (isIE && this.tagName == "INPUT" && a == "type") {
                    var t = this.outerHTML.split(a + "=" + this.attr(a));
                    if (t.length > 1) {
                        this.outerHTML = t.join(a + "=" + s);
                    } else {
                        this.outerHTML = this.outerHTML.replace(">", " " + a + "=" + s + ">");
                    };
                } else {
                    this.setAttribute(a, s);
                    return this.id == '' ? this : $(this.id);
                };
            };
        },
        ec: function(s) {
            return this.cn().ec(s);
        },
        ac: function(s) {
            this.cn(this.cn().ac(s));
            return this;
        },
        dc: function(s) {
            var me = this,
                c = this.cn();
            me.cn(c.dc(s));
            return me;
        },
        tc: function(s) {
            this.cn(this.cn().tc(s));
            return this;
        },
        chn: function(n) {
            return $(this.childNodes[n]);
        },
        chr: function(n) {
            return $(this.children[n]);
        },
        cn: function(s) {
            if (s || s == '') {
                this.className = s;
                return this;
            } else {
                return this.className
            }
        },
        cs: function(s) {
            if (isIE) {
                if (s == "top") {
                    return this.offsetTop;
                };
                if (s == "left") {
                    return this.offsetLeft;
                };
                if (s == "width") {
                    return this.offsetWidth;
                };
                if (s == "height") {
                    return this.offsetHeight;
                };
                if (s == "background-position" && +$('').split(',')[1] < 9) {
                    return this.currentStyle["backgroundPositionX"] + " " + this.currentStyle["backgroundPositionY"];
                };
                return this.currentStyle[s.camelize()];
            } else {
                return window.getComputedStyle(this, null).getPropertyValue(s);
            }
        },
        csn: function(s) {
            return $.m.p(this.cs(s));
        },
        css: function(s) {
            var me = this,
                l = s.split(';');
            l.ec(function(i) {
                var t = this[i].split(':'),
                    s;
                if (t[2]) {
                    s = t[1] + ":" + t[2];
                } else {
                    s = t[1];
                };
                if (t[0] == 'float') {
                    if (isIE) {
                        t[0] = 'style-float';
                    } else {
                        t[0] = 'css-float';
                    }
                };
                if (t[0]) {
                    $S(me)[t[0].camelize()] = s;
                };
            });
            return me;
        },
        evt: function(s, f, c) {
            if (c == undefined) {
                c = false;
            };
            if (isFF && s == "mousewheel") {
                s = 'DOMMouseScroll';
            };
            isIE ? this.attachEvent('on' + s, f, c) : this.addEventListener(s, f, c);
            return this;
        },
        revt: function(s, f, c) {
            if (c == undefined) {
                c = false;
            };
            isIE ? this.detachEvent('on' + s, f, c) : this.removeEventListener(s, f, c);
            return this;
        },
        fevt: function(s) {
            if ($D.createEventObject) {
                var e = $D.createEventObject();
                this.fireEvent('on' + s, e);
            } else {
                var e = $D.createEvent("HTMLEvents");
                e.initEvent(s, true, true);
                this.dispatchEvent(e);
            };
            return this;
        },
        fc: function() {
            return $(this.firstChild);
        },
        insertA: function(o) {
            return o.insertAdjacentElement("afterEnd", this.cloneNode(true));
        },
        insertB: function(o) {
            return o.insertAdjacentElement("beforeBegin", this.cloneNode(true));
        },
        moveA: function(o) {
            var a = this.insertA(o);
            this.r();
            return a;
        },
        moveB: function(o) {
            var a = this.insertB(o);
            this.r();
            return a;
        },
        ps: function() {
            return $(this.previousSibling);
        },
        ns: function() {
            return $(this.nextSibling);
        },
        fcs: function() {
            this.focus();
            return this;
        },
        find: function(s, c) {
            return (function f(s, o, c) {
                var r = RegExp,
                    o = o || $D,
                    s = !s || s == '.' ? '*' : s;
                if (o.length === 0) return [];
                if (/^(\w+|\*)$/.test(s)) return o.getElementsByTagName(s);
                if (/^#(\w+)(?:[\s>]?(.*))?$/.test(s)) return r.$2 ? f(r.$2, o.getElementById(r.$1)) : o.getElementById(r.$1);
                if (/^\.(.*)$/.test(s)) {
                    c = (c ? r.$1 : 'class=' + r.$1).split('=');
                    for (var t, i = 0, ci, a = [], o = o.length ? o : o.getElementsByTagName('*'); ci = o[i++];)(t = ci.getAttributeNode(c[0])) && (c[1] ? t.value == c[1] : 1) && a.push(ci);
                    return a;
                };
                if (/^(\w+)(\..*)$/.test(s)) return f(r.$2, f(r.$1, o));
                if (/^(\w+):(.*)$/.test(s)) return f("." + r.$2, f(r.$1, o), 1);
                return [];
            })(s, this, c);
        },
        replaceHtml: function(s) {
            var e = this.cloneNode(false),
                d = this.parentNode ? this.parentNode : $D;
            e.innerHTML = s;
            d.replaceChild(e, this);
            return this;
        },
        h: function(s) {
            if (s || s == '') {
                this.innerHTML = s;
                return this
            } else return this.innerHTML;
        },
        ht: function(s) {
            if (this.innerText) {
                if (s || s == '') {
                    this.innerText = s;
                    return this;
                } else {
                    return this.innerText || '';
                };
            } else {
                if (s || s == '') {
                    this.textContent = s;
                    return this
                } else {
                    return this.textContent || '';
                };
            };
        },
        hide: function() {
            return this.css('display:none');
        },
        pos: function(p) {
            var x = 0,
                y = 0,
                w = 0,
                h = 0;
            p = p || $DB;
            if (this.getBoundingClientRect) {
                var box = this.getBoundingClientRect();
                x = box.left + Math.max($DE.scrollLeft, $DB.scrollLeft) - $DE.clientLeft;
                y = box.top + Math.max($DE.scrollTop, $DB.scrollTop) - $DE.clientTop;
            } else {
                for (; obj != p; x += obj.offsetLeft, y += obj.offsetTop, obj = obj.offsetParent) {};
            };
            w = this.offsetWidth;
            h = this.offsetHeight;
            return {
                x: x,
                y: y,
                w: w,
                h: h
            };
        },
        posFix: function() {
            return {
                x: this.getBoundingClientRect().left,
                y: this.getBoundingClientRect().top,
                w: this.offsetWidth,
                h: this.offsetHeight
            };
        },
        //getBoundingClientRect 来替换pos方法
        pn: function(n) {
            if (!n) {
                return $(this.parentNode)
            };
            var p = this;
            while (n) {
                p = p.parentNode;
                n--;
            };
            return $(p);
        },
        r: function() {
            if (this && this.parentNode) this.parentNode.removeChild(this);
        },
        val: function(s) {
            if (s || s == '') {
                return this.value = s, this;
            } else {
                return this.value;
            }
        },
        show: function() {
            return this.css('display:block');
        },
        print: function() {
            var _chs = this.childNodes,
                html = "<!DOCTYPE html><html><head charset='gb2312'><title>" + ($D.title || '文档打印') + "</title>",
                _wwh = $.wh();
            var _sAry = $D.getElementsByTagName("style"),
                _lAry = $D.getElementsByTagName("link");
            for (var i = 0, _len = _sAry.length; i < _len; i++) {
                html += "<style type='text/css'>" + _sAry[i].innerHTML + "</style>";
            };
            for (var i = 0, _len = _lAry.length; i < _len; i++) {
                html += _lAry[i].outerHTML;
            };
            html += "<style media=print>.Noprint{display:none;}.PageNext{page-break-after: always;}</style></head><body><div class='wp hp'>";
            for (var i = 0, _len = _chs.length; i < _len; i++) {
                var _node = _chs[i];
                if (_node.nodeType == 3) {
                    html += _node.nodeValue;
                } else {
                    html += _node.outerHTML;
                };
            };
            html += "</div><input type='button' class='Noprint' style='position:absolute;top:10px;right:50px;width:80px;' value='打印' onclick='window.print();'></body></html>";
            var _window = window.open('about:blank', '', 'height=' + (_wwh[1] * 2 - 100) + ', width=' + (_wwh[0] * 2 - 100) + ', top=50, left=50, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no'),
                _wd = _window.document;
            return _wd.open(), _wd.write(html), _wd.close(), this;
        }
    };//---end---dom

    var _number = {
        round: function(p) {
            p = $M.pow(10, p || 0);
            return $M.round(this * p) / p;
        }
    };//---end---number

    var _o = {
        ec: function(fn) {
            for (var k in this) {
                if (this.hasOwnProperty(k)) {
                    fn(k, this[k], this);
                };
            };
        },
        clone: function() {
            if (this && this.h == undefined) {
                switch ($.getType(this)) {
                    case 'object':
                        return $.JSON.decode($.JSON.encode(this));
                    case 'array':
                        return this.copy();
                    default:
                        return this;
                };
            };
        },
        concat: function(a) {
            if (a && $.getType(a) == 'object') {
                for (var k in a) {
                    if (this[k] === undefined || this[k] === null) {
                        this[k] = a[k];
                    };
                };
            };
            return this;
        },
        copyTo: function(a) {
            if (a && $.getType(a) == 'object') {
                for (var k in this) {
                    if (this[k] !== undefined && this[k] !== null) {
                        a[k] = this[k];
                    };
                };
            };
            return a;
        },
        extend: function(fn, a) {
            return fn.apply ? (fn.apply(this, a), this) : this;
        }
    };

    var _w = {
        timeIntervalArray: [],
        isIE: isIE,
        isPad: isPad,
        $D: $D,
        $DB: $DB,
        $B: $DB,
        $Ef: function(s) {
            return $(s);
        },
        $DBf: function() {
            return $DB;
        },
        $Fg: function() {
            return $($D.createDocumentFragment());
        },
        $C: function(id, tag) {
            if (tag) {
                var e = $D.createElement(tag);
                if (id != '' && id != null) e.setAttribute('id', id);
                return $(e);
            } else {
                return $D.createElement(id);
            }
        },
        $$: function() {
            return this.$A(Sizzle(str));
        },
        $A: function(o, b) {
            if (!o) {
                return [];
            };
            if (o.toArray) {
                return o.toArray();
            };
            var l = o.length || 0,
                r = new Array(l);
            while (l--) {
                r[l] = o[l];
            };
            return r;
        },
        $S: function(s) {
            if (!s) return null;
            return (typeof(s) == 'string' ? $(s).style : s.style);
        }
    };//---end---windows;

    var _tween = {
        easeNone: function (t, b, c, d) { return c * t / d + b; },
        easeInQuad: function (t, b, c, d) { return c * (t /= d) * t + b; },
        easeOutQuad: function (t, b, c, d) { return -c * (t /= d) * (t - 2) + b; },
        easeInOutQuad: function (t, b, c, d) { if ((t /= d / 2) < 1) { return c / 2 * t * t + b; }; return -c / 2 * ((--t) * (t - 2) - 1) + b; },
        easeInCubic: function (t, b, c, d) { return c * (t /= d) * t * t + b; },
        easeOutCubic: function (t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; },
        easeInOutCubic: function (t, b, c, d) { if ((t /= d / 2) < 1) { return c / 2 * t * t * t + b; }; return c / 2 * ((t -= 2) * t * t + 2) + b; },
        easeOutInCubic: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutCubic(t * 2, b, c / 2, d); }; return _tween.easeInCubic((t * 2) - d, b + c / 2, c / 2, d); },
        easeInQuart: function (t, b, c, d) { return c * (t /= d) * t * t * t + b; },
        easeOutQuart: function (t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; },
        easeInOutQuart: function (t, b, c, d) { if ((t /= d / 2) < 1) { return c / 2 * t * t * t * t + b; }; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; },
        easeOutInQuart: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutQuart(t * 2, b, c / 2, d); }; return _tween.easeInQuart((t * 2) - d, b + c / 2, c / 2, d); },
        easeInQuint: function (t, b, c, d) { return c * (t /= d) * t * t * t * t + b; },
        easeOutQuint: function (t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; },
        easeInOutQuint: function (t, b, c, d) { if ((t /= d / 2) < 1) { return c / 2 * t * t * t * t * t + b; }; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; },
        easeOutInQuint: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutQuint(t * 2, b, c / 2, d); }; return _tween.easeInQuint((t * 2) - d, b + c / 2, c / 2, d); },
        easeInSine: function (t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; },
        easeOutSine: function (t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b; },
        easeInOutSine: function (t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; },
        easeOutInSine: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutSine(t * 2, b, c / 2, d); }; return _tween.easeInSine((t * 2) - d, b + c / 2, c / 2, d); },
        easeInExpo: function (t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b - c * 0.001; },
        easeOutExpo: function (t, b, c, d) { return (t == d) ? b + c : c * 1.001 * (-Math.pow(2, -10 * t / d) + 1) + b; },
        easeInOutExpo: function (t, b, c, d) { if (t == 0) { return b; }; if (t == d) { return b + c; }; if ((t /= d / 2) < 1) { return c / 2 * Math.pow(2, 10 * (t - 1)) + b - c * 0.0005; }; return c / 2 * 1.0005 * (-Math.pow(2, -10 * --t) + 2) + b; },
        easeOutInExpo: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutExpo(t * 2, b, c / 2, d); }; return _tween.easeInExpo((t * 2) - d, b + c / 2, c / 2, d); },
        easeInCirc: function (t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b; },
        easeOutCirc: function (t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; },
        easeInOutCirc: function (t, b, c, d) { if ((t /= d / 2) < 1) { return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; }; return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b; },
        easeOutInCirc: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutCirc(t * 2, b, c / 2, d); }; return _tween.easeInCirc((t * 2) - d, b + c / 2, c / 2, d); },
        easeInElastic: function (t, b, c, d, a, p) { var s; if (t == 0) { return b; }; if ((t /= d) == 1) { return b + c; }; if (!p) { p = d * .3; }; if (!a || a < Math.abs(c)) { a = c; s = p / 4; } else { s = p / (2 * Math.PI) * Math.asin(c / a); }; return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; },
        easeOutElastic: function (t, b, c, d, a, p) { var s; if (t == 0) { return b; }; if ((t /= d) == 1) { return b + c; }; if (!p) { p = d * .3; }; if (!a || a < Math.abs(c)) { a = c; s = p / 4; } else { s = p / (2 * Math.PI) * Math.asin(c / a); }; return (a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b); },
        easeInOutElastic: function (t, b, c, d, a, p) { var s; if (t == 0) { return b; }; if ((t /= d / 2) == 2) { return b + c; }; if (!p) { p = d * (.3 * 1.5); }; if (!a || a < Math.abs(c)) { a = c; s = p / 4; } else { s = p / (2 * Math.PI) * Math.asin(c / a); }; if (t < 1) { return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; }; return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b; },
        easeOutInElastic: function (t, b, c, d, a, p) { if (t < d / 2) { return _tween.easeOutElastic(t * 2, b, c / 2, d, a, p); }; return _tween.easeInElastic((t * 2) - d, b + c / 2, c / 2, d, a, p); },
        easeInBack: function (t, b, c, d, s) { if (s == undefined) { s = 1.70158; }; return c * (t /= d) * t * ((s + 1) * t - s) + b; },
        easeOutBack: function (t, b, c, d, s) { if (s == undefined) { s = 1.70158; }; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; },
        easeInOutBack: function (t, b, c, d, s) { if (s == undefined) { s = 1.70158; }; if ((t /= d / 2) < 1) { return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; }; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; },
        easeOutInBack: function (t, b, c, d, s) { if (t < d / 2) { return _tween.easeOutBack(t * 2, b, c / 2, d, s); }; return _tween.easeInBack((t * 2) - d, b + c / 2, c / 2, d, s); },
        easeInBounce: function (t, b, c, d) { return c - _tween.easeOutBounce(d - t, 0, c, d) + b; },
        easeOutBounce: function (t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; }; },
        easeInOutBounce: function (t, b, c, d) { if (t < d / 2) { return _tween.easeInBounce(t * 2, 0, c, d) * .5 + b; } else { return _tween.easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b; }; },
        easeOutInBounce: function (t, b, c, d) { if (t < d / 2) { return _tween.easeOutBounce(t * 2, b, c / 2, d); }; return _tween.easeInBounce((t * 2) - d, b + c / 2, c / 2, d); }
    };//---end---tween

    var _load = {
        loadjs: function(url, callback, part) {
            if (!url) {
                return false;
            }
            var _stAry = document.getElementsByTagName('script'),
                _cbfn = callback || _fn;
            for (var i = 0, _sLen = _stAry.length; i < _sLen; i++) {
                if (_stAry[i].src == url) {
                    _cbfn(_stAry[i]);
                    return;
                }
            }
            var eDom = document.getElementsByTagName(part || 'body').item(0),
                script = document.createElement('script');
            script.onload = script.onreadystatechange = script.onerror = function() {
                if (script && script.readyState && /^(?!(?:loaded|complete)$)/.test(script.readyState)) {
                    return;
                }
                script.onload = script.onreadystatechange = script.onerror = null;
                _cbfn(script);
                if (script) {
                    script.src = '';
                    script.parentNode.removeChild(script);
                    script = null;
                };
            };
            script.type = 'text/javascript';
            script.charset = "utf-8";
            script.src = url;
            try {
                eDom.appendChild(script);
            } catch (e) {
                _cbfn(e.message)
            };
        },
        loadcss: function(url, callback, part) {
            if (!url) {
                return false;
            }
            var _stAry = document.getElementsByTagName('link'),
                _cbfn = callback || _fn;
            for (var i = 0, _sLen = _stAry.length; i < _sLen; i++) {
                if (_stAry[i].href == url) {
                    _cbfn(_stAry[i]);
                    return;
                }
            }
            var eDom = document.getElementsByTagName(part || 'body').item(0),
                link = document.createElement('link');
            link.onload = link.onreadystatechange = link.onerror = function() {
                if (link && link.readyState && /^(?!(?:loaded|complete)$)/.test(link.readyState)) {
                    return;
                }
                link.onload = link.onreadystatechange = link.onerror = null;
                _cbfn(link);
            };
            link.type = 'text/css';
            link.rel = 'Stylesheet';
            link.charset = "utf-8";
            link.href = url;
            try {
                eDom.appendChild(script);
            } catch (e) {};
        }
    };//---end---load

    var _ajax = {
        XHR: function () {
            var me = this, XHR = getR(), ifRun = false;
            function getR() {
                if (!window.ActiveXObject) { return new XMLHttpRequest(); }
                var e = "MSXML2.XMLHTTP", t = ["Microsoft.XMLHTTP", e, e + ".3.0", e + ".4.0", e + ".5.0", e + ".6.0"], _len = t.length;
                for (var n = _len - 1; n > -1; n--) { try { return new ActiveXObject(t[n]); } catch (r) { continue; }; };
            }
            function exec(f, args) { return function () { return f.apply(me, args); }; };
            function onStateChange() {
                if (XHR.readyState == 4) {
                    var e = XHR.status, t = XHR.responseText;
                    var _onSucc = arguments[0], _onErr = arguments[1], _timeoutID = arguments[2];
                    if (e >= 400 && e < 500) { _onErr("Clinet Error," + e); return; }
                    if (e >= 500) { _onErr("Server Error," + e); return; }
                    if (e == 200) { _onSucc(t); } else { _onErr(t); }
                    clearInterval(_timeoutID);
                    ifRun = false;
                    return t;
                }
            };
            me.getState = function () { return ifRun; };
            me.request = function (url, args, cbFn, method, async) {
                if (ifRun) { return; }; ifRun = true;
                var _url = url || '', _args = args || '', _f = cbFn || {}, _m = method || 'POST', _async = async !== null ? async : true;
                var _onSucc = _f.onSuccess || _fn, _onErr = _f.onError || _fn, _onTO = _f.onTimeout || _fn;
                var _timeoutFn = setTimeout(function () { XHR.abort(); clearInterval(_timeoutFn); _onErr("Timeout"); _onTO(); }, 2e4);
                //XHR.withCredentials = true;
                if (_m == 'POST') {
                    XHR.open("POST", _url, _async);
                    XHR.onreadystatechange = exec(onStateChange, [_onSucc, _onErr, _timeoutFn]);
                    //XHR.setRequestHeader("Access-Control-Allow-Origin", "*");
                    //XHR.setRequestHeader("Access-Control-Allow-Credentials", true);
                    XHR.setRequestHeader("X-Requested-With", "XMLHttpRequest");
                    XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
                    XHR.send(_args);
                } else {
                    XHR.open("GET", _url + "?" + _args, _async);
                    XHR.onreadystatechange = exec(onStateChange, [_onSucc, _onErr, _timeoutFn]);
                    //XHR.setRequestHeader("Access-Control-Allow-Origin", "*");
                    //XHR.setRequestHeader("Access-Control-Allow-Credentials", true);
                    XHR.send(null);
                }
            }
            if (arguments.length) { me.request(arguments[0], arguments[1], arguments[2], arguments[3]); };
            return me;
        },
        XHRPool: function (j) {
            var me = this, _j = j || {};
            var _ary = [], _max = _j.max || 5;
            function addXHR() { var _xhr = new _ajax.XHR(); _ary.push(_xhr); return _xhr; };
            me.getXHR = function () { for (var i = 0; i < _ary.length; i++) { if (!_ary[i].getState()) { return _ary[i]; }; }; return addXHR(); };
            me.getLength = function () { return _ary.length; };
        }
    };//---end---ajax

    $.idle = function (){ };
    $.namespace = function (S, context) {
        var context = context || window;
        var A = S.split('.'), A1 = A[0], obj = context[A1];
        if (!obj) {
            obj = {};
            context[A1] = obj;
        };
        for (var i = 1, _iLen = A.length; i < _iLen; i++) {
            var T = A[i];
            if (!obj[T]) {
                obj[T] = {};
                obj = obj[T];
            };
        };
        return obj;
    };

    $.toArgsObj = function(argsStr) {
        if (typeof argsStr == 'object') {
            return argsStr;
        }
        var _kvAry = argsStr.split('&'),
            _len = _kvAry.length,
            _kv = {};
        for (var i = 0; i < _len; i++) {
            var _sAry = _kvAry[i].split('=');
            _kv[_sAry[0]] = _sAry[1];
        }
        return _kv;
    }

    $.toArgsString = function (obj) {
        switch ($.getType(obj)) {
            case 'string':
                return obj;
            case 'object':
                var _t = [], k;
                for (k in obj) {
                    if (obj.hasOwnProperty(k)) {
                        _t.push(k + '=' + ($.getType(obj[k]) == 'object' ? $.JSON.encode(obj[k]) : obj[k]));
                    }
                }
                return _t.join('&');
            case 'array':
                return obj.join('&');
            default:
                return '';
        }
    };

    $.ext = function (e, o) {
        if (e === null || o === null) {
            return;
        }
        for (var i in o) {
            try {
                if (o.hasOwnProperty(i) && !e[i]) {
                    e[i] = o[i]
                }
            } catch (e) {

            }
        }

        return e;
    };

    $.init = function (o, n) {
        var _o = o || {}, _n = n || {};
        for (var i in n) {
            if (_o[i] == null) {
                _o[i] = _n[i];
            } else {
                if (i == 'p') {
                    _o[i] = $(_o[i]);
                }
            }
        }

        return _o;
    }

    $.skin = {
        classObj: {},
        setAtomStyle: function (o) { this.classObj = o;},
        getStyle: function () {
            var css = null;
            try {
                css = document.styleSheets[0];
                if (!css) {
                    var head = $D.getElementsByTagName("head").item(0);
                    head.appendChild($C("style"));
                    css = $D.styleSheets[0];
                };
            } catch (ex) {
                css = $D.createStyleSheet("styles.css");
            }

            return css;
        },
        setStyle:function(css, selector, rule) {
            if (css.insertRule) { // ff
                css.insertRule(""+selector+" { "+rule+" }", css.cssRules.length);
            } else if(css.addRule) { // ie
                try{
                    css.addRule(selector, rule);
                }catch(e){

                }
            }
        },
        setCssItem: function (s1, s2) {
            this.setStyle(this.getStyle(), s1, s2);
            return this;
        },
        setCss: function (o) {
            if ($.getType(o) == 'object') {
                var css = this.getStyle();
                for (var i in o) {
                    this.setStyle(css, i, o[i]);
                }
            }

            return css;
        }
    }

    $.style = function (styles){
        $.skin.setCss(styles);
    }

    $.path = function (path, context, value){
        if(!path){
            return;
        }
        var _temps = path.split('.'),
            _tempLen = _temps.length,
            _curr = context || window,
            _temp,
            _value,
            i = 0;

        if(value){
            _tempLen = _tempLen - 1;
        }

        for(; i < _tempLen; i++){
            _temp = _temps[i];
            if(_curr.get){
                _curr = _curr.get(_temp);
            }else {
                if(value){
                    _curr = _curr[_temp] = _curr[_temp] || {};
                }else {
                    _curr = _curr[_temp];
                }
            }
        }

        _temp = _temps[i];

        if(value && _curr){
            if (_curr.set) {
                _curr.set(_temp, value);
            } else {
                _curr[_temp] = value;
            }

            _curr = value;
        }

        return _curr;
    }

    var __baseMethods__ = {
        render: function (view, data){
            if(!view){
                return console.error('view is null'), false;
            }

            var _name = view.name || '$root',
                _props = view.props || {},
                _events = view.events,
                _content = view.content,
                _templete = view.templete,
                _items = view.items,
                _type = view.type,
                _view = null,
                _self = this;

            data = data || {};
            data.parent = data.parent || $DB;

            for(var _key in _props){
                if(data[_key] == null){
                    data[_key] = _props[_key];
                }
            }

            if(_type){
                var _comp = $.path(_type);
                if(_comp){
                    _view = new _comp(data);
                }else {
                    return console.error('在系统中未找到相关UI组件:' + _type);
                }
            }else {
                _view = data.parent.adElm(view.tag||'div');
                _view.dom = _view;
            }

            if(!_view){
                return console.error('view不存在');
            }

            if(!this.root){
                this.root = _view;
                this.dom = _view.dom;
            }

            this.views[_name] = _view;

            var _dom = _view.dom,
                _value;

            _props.class = _props.class || view.class;
            _props.style = _props.style || view.style;

            for(var _key in _props){
                _value = _props[_key];
                switch(typeof _value){
                    case 'function':
                        _value = _value.call(this, _key);
                        break;
                    case 'string':
                        var _len = _value.length - 1;
                        if(_value.indexOf('{')==0 && _value.indexOf('}') == _len){
                            _value = _value.substring(1, _len);

                            this.watch(_value, (function (key, view){
                                return function (name, oldValue, value){
                                    //console.log(name, oldValue, value);
                                    if(value){
                                        if(view.attr){
                                            view.attr(key, value);
                                        }else if(_view.set){
                                            view.set(key, value);
                                        }
                                    }
                                }
                            })(_key, _view), this);


                            _value = null;
                            //_value = $.path(_value, this);
                        }
                        break;
                }

                if(_value){
                    if(_view.attr){
                        _view.attr(_key, _value);
                    }else if(_view.set){
                        _view.set(_key, _value);
                    }
                }
            }

            if(_events){
                for(var _key in _events){
                    _value = _events[_key];
                    if(typeof _value == 'string'){
                        _value = this[_value];
                    }
                    if(_value && _view.dom){
                        if(_view.views){
                            _view.on(_key, _value, this);
                        }else {
                            _dom.evt(_key, function (e){
                                _value.call(_self, $.e.fix(e), _self);
                            });
                        }
                    }
                }
            }

            switch($.getType(_content)){
                case 'array':
                    for(var i = 0, _len = _content.length; i < _len; i++){
                        _value = _content[i];
                        if(_value){
                            this.render(_value, $.init(this.argvs[_value.name] || {}, { parent: _dom }));
                        }
                    }
                    break;
                case 'string':
                    _value = _content;
                    var _len = _value.length - 1;
                    if(_value.indexOf('{')==0 && _value.indexOf('}') == _len){
                        _value = _value.substring(1, _len);
                        this.watch(_value, function (name, oldValue, _value){ _view.dom.h(_value); }, this);
                        _value = $.path(_value, this);
                    }
                    _view.dom.h(_value);
                    break;
                case 'object':
                    this.render(_content, $.init(this.argvs[_content.name] || {}, { parent: _dom }));
                    break;
            }

            return _view;
        },
        member: function (name) {
            return this.constructor.__props__[name];
        },
        get: function (key){
            var _prop = this.member(key);
            if(_prop){
                return _prop.getter.call(this);
            }
        },
        set: function (key, value){
            var _prop = this.member(key);
            if(_prop){
                if(key=='views'){
                    for(var _key in value){
                        var _view = this.views[_key];
                        if(_view){
                            value.parent = _view;
                            new value.type(value);
                        }
                    }
                }else {
                    return _prop.setter.call(this, value);
                }
            }
        },
        gets: function (){
            var _props = this.constructor.__props__,
                _values = {};

            for(var key in _props){
                _values[key] = _props[key].getter.call(this);
            }

            return _values;
        },
        sets: function (values){
            for(var key in values){
                this.set(key, values[key]);
            }
        },
        destory: function (){
            this._watchers_ = null;
            this._listeners_ = null;
        },
        watch: function (name, handler, context){
            var _watchers_ = this._watchers_[name] = this._watchers_[name]|| [ ];
            if(_watchers_ && handler){
                _watchers_.push({
                    name: name,
                    handler: handler,
                    context: context || this
                });
            }
        },
        unwatch: function (name, handler, context){
            var _watchers_ = this._watchers_[name],
                _watcher,
                _context = context || this;
            if(_watchers_ && handler){
                for(var i= 0, _len = _watchers_.length; i<_len; i++){
                    _watcher = _watchers_[i];
                    if(_watcher.name === name && _watcher.handler === handler && _watcher.context === _context){
                        _watchers_.splice(i, 0);
                    }
                }
            }
        },
        notify: function (name, oldValue, newValue){
            var _watchers_ = this._watchers_[name],
                _watcher;
            if(_watchers_){
                for(var i= 0, _len = _watchers_.length; i<_len; i++){
                    _watcher = _watchers_[i];
                    _watcher.handler.call(_watcher.context, name, oldValue, newValue);
                }
            }
        },
        on: function (name, handler, context){
            var _listeners = this._listeners_[name] = this._listeners_[name]||[ null ];
            if(_listeners && handler){
                _listeners.push({
                    name: name,
                    handler: handler,
                    context: context || this
                });
            }
        },
        off: function (name, handler, context){
            var _listeners = this._listeners_[name],
                _listener,
                _context = context || this;
            if(_listeners && handler){
                for(var i= 0, _len = _listeners.length; i<_len; i++){
                    _listener = _listeners[i];
                    if(_listener.name === name && _listener.handler === handler && _listener.context === _context){
                        _listeners.splice(i, 0);
                    }
                }
            }
        },
        upon: function (name, handler, context){
            var _listeners = this._listeners_[name];
            if(_listeners && handler){
                _listeners[0] = {
                    name: name,
                    handler: handler,
                    context: context || this
                };
            }
        },
        fire: function (name, data){
            var _listeners = this._listeners_[name],
                _listener;
            if(_listeners){
                for(var i= 0, _len = _listeners.length; i<_len; i++){
                    _listener = _listeners[i];
                    if(_listener && _listener.handler){
                        _listener.handler.call(_listener.context, data, this, _listener.name);
                    }
                }
            }
        }
    };

    $.uuid = function (){
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        }).toUpperCase();
    }

    $.import = function (imports, callback){

    }

    $.define = function (name, meta){
        if(!name||!meta){
            return console.error('classname or meta is invalid.');
        }
        $.style(meta.style);

        var _methods = meta.methods || {},
            _props = meta.props || {},
            _init = _methods.init || function (){ };

        var FilyClass = function (args){
            var _ctor = this.constructor,
                _meta = _ctor.__meta__ || {};

            this._listeners_ = {};
            this._watchers_ = {};

            if(_meta.view){
                this.views = {};
                this.argvs = {};
                this.render(_meta.view, args);
            }

            if(_meta.events){
                for(var i= 0, _len = _meta.events.length; i<_len; i++){
                    this._listeners_[_meta.events[i]] = [ null ];
                }
            }

            this.sets(args);

            if(args.events){
                for(var key in args.events){
                    this.on(key, args.events[key], this);
                }
            }

            _ctor.__init__.call(this, args);

            return this;
        }

        $.ext(_methods, __baseMethods__);

        for(var _propKey in _props){
            var _value = _props[_propKey],
                _getter = null,
                _setter = null;

            if($.getType(_value)=='object'){
                _getter = _value.get;
                _setter = _value.set;
                _value = _value.value;
            }

            if(!_getter){
                _getter = (function (value, propKey){
                    return function (){
                        return this['_'+propKey] || value;
                    }
                })(_value, _propKey);
            }

            if(!_setter){
                _setter = (function (propKey){
                    return function (value){
                        this['_'+propKey] = value;
                    }
                })(_propKey);
            }

            _props[_propKey] = {
                getter: _getter,
                setter: (function (_setter, _propKey){
                    return function (value){
                        var _oldValue = this.get(_propKey);
                        if(_oldValue != value){
                            _setter.call(this, value);
                        }
                        this.notify(_propKey, _oldValue, value);
                    }
                })(_setter, _propKey),
                value: _value
            }
        }

        for(var _methodKey in _methods){
            FilyClass.prototype[_methodKey] = _methods[_methodKey];
        }

        FilyClass.__init__ = _init;
        FilyClass.__meta__ = meta;
        FilyClass.__props__ = _props;

        $.path(name, window, FilyClass);

        return FilyClass;
    }

    $.ajax = function (a) {
        var _args = { url: '', data: '', args: '', method: 'GET', async: true, dataType: 'json', onStart: _fn, onSuccess: _fn, onError: _fn, onTimeOut: _fn, onComplete: _fn };
        _args = $.init(a, _args);
        var _now = new Date(), _rand = _now.date8() + _now.getHours() + _now.getMinutes() + _now.getSeconds();
        var _cb = 'fily_' + _rand + '_' + Math.random().toString().replace('.', ''), _dt = _args.dataType||'json';
        switch (_dt.toLowerCase()) {
            case 'html':
                _args.method = 'GET'; _args.data = 'cb';
            case 'json':
            case 'text':
                if (!window.ajaxObjPool) {
                    window.ajaxObjPool = new _ajax.XHRPool({ max: 5 });
                }
                window.ajaxObjPool.getXHR().request(_args.url, $.toArgsString(_args.data || _args.args) + '&clienttime=' + _rand, _args, _args.method, _args.async);
                break;
            case 'jsonp':
                window[_cb] = function (data) {
                    _args.onSuccess(data);
                }
                _load.loadjs(_url + '?callback=' + _cb + '&' + $.toArgsString(_args.data || _args.args)) + '&clienttime=' + _rand;
                break;
        }

        return $;
    }

    $.animate = function (a) {
        var _args = $.init(a, {
            begin: 0,
            end: 100,
            speed: 16,
            easing: 'easeInQuad',
            interval: 500,
            onRunning: _fn,
            onComplete: _fn
        });

        if (_args.begin == _args.end) {
            return $;
        }

        var n = 0, _during = _args.interval, _start = setTimeout(exce, _args.speed);

        function exce() {
            n += _args.speed * 2;
            if (n >= _during) {
                _args.onRunning({ value: _args.end });
                _args.onComplete({ value: _args.end });
                clearTimeout(_start);
            } else {
                var _val = _tween[_args.easing](n, _args.begin, (_args.end - _args.begin), _during);
                _args.onRunning({ value: _val });
                setTimeout(exce, _args.speed);
            }
        }

        return $;
    }

    $.q = function (j) {
        var me = this, _j = j || {}, _fn = function () { };
        var a = [], sat = 0, delay = _j.delay;
        var _onFinish = _j.onFinish || function () { console.log('end'); };
        var ifStop = false;
        if (delay == null) { delay = 2000; }
        function exec(cbFn) {
            var obj = a.shift(), _cf = cbFn || _fn;
            if (!obj) { return; }
            var _f = obj.f || _fn, _args = obj.args || [];
            _f.apply(_f, _args);
            if (_cf() != false) { me.next(); }
        }
        me.push = function (o) { a.push(o); return me; }
        me.go = function (cbFn) { if (sat == 1 || !a.length) { return me; }; sat = 1; exec(cbFn); return me; }
        me.remove = function (v) { a.re(v); return me; }
        me.next = function (cbFn, ifRestart) {
            var _irs = ifRestart || false;
            if (_irs) { sat = 1; }
            if (ifStop || !sat) { return me; }
            if (!a.length) { sat = 0; _onFinish(me); return me; }
            if (delay) { setTimeout(function () { exec(cbFn); }, delay); } else { exec(cbFn); }
            return me;
        }
        me.stop = function () { ifStop = true; return me; }
        me.start = function () { ifStop = false; me.next(); return me; }
        me.len = function () { return a.length; }
        me.clear = function () { a.clear(); return me; }
        return me;
    }

    $.date = function () {
        var me = this;
        var now = new Date();                                                //当前日期
        var nowDayOfWeek = (now.getDay() == 0) ? 7 : now.getDay() - 1;       //今天是本周的第几天。周一=0，周日=6
        var nowDay = now.getDate();                                          //当前日
        var nowMonth = now.getMonth();                                       //当前月值（1月=0，12月=11）
        var nowMonReal = now.getMonth() + 1;                                 //当前月实际数字
        var nowYear = now.getFullYear();                                     //当前年
        function AddDays(d, n) { var t = new Date(d); t.setDate(t.getDate() + n); return t; };//日期+天
        function AddMonths(d, n) { var t = new Date(d); t.setMonth(t.getMonth() + n); if (t.getDate() != d.getDate()) { t.setDate(0); }; return t; }; //日期+月。日对日，若目标月份不存在该日期，则置为最后一日
        function AddYears(d, n) { var t = new Date(d); t.setFullYear(t.getFullYear() + n); if (t.getDate() != d.getDate()) { t.setDate(0); }; return t; };//日期+年。月对月日对日，若目标年月不存在该日期，则置为最后一日
        me.getQuarterStartMonth = function () { if (nowMonth <= 2) { return 0; } else if (nowMonth <= 5) { return 3; } else if (nowMonth <= 8) { return 6; } else { return 9; }; };//获得本季度的开始月份
        me.getWeekStartDate = function () { return AddDays(now, -nowDayOfWeek); }; //周一
        me.getWeekEndDate = function () { return AddDays(me.getWeekStartDate(), 6); }; //周日。本周一+6天
        me.getMonthStartDate = function () { return new Date(nowYear, nowMonth, 1); }; //月初
        me.getMonthEndDate = function () { return AddDays(AddMonths(me.getMonthStartDate(), 1), -1); }; //月末。下月初-1天
        me.getQuarterStartDate = function () { return new Date(nowYear, me.getQuarterStartMonth(), 1); }; //季度初
        me.getQuarterEndDate = function () { return AddDays(AddMonths(me.getQuarterStartDate(), 3), -1); }; //季度末。下季初-1天
    }

    $.m = {
        p: function (a) { return parseInt(a, 10);},
        pf: parseFloat,
        toDecimal: function (x) { return isNaN(parseFloat(x)) ? false : Math.round(x * 100) / 100; }, //功能：保留两位小数 -- 将浮点数四舍五入，取小数点后2位
        toDecimal2: function (x) { if (isNaN(parseFloat(x))) { return false; }; var s = (Math.round(x * 100) / 100).toString(); var rs = s.indexOf('.'); if (rs < 0) { rs = s.length; s += '.'; }; while (s.length <= rs + 2) { s += '0'; }; return s; },//制保留2位小数，如：2，会在2后面补上00.即2.00  
        fomatFloat: function (src, pos) { return Math.round(+src * Math.pow(10, pos)) / Math.pow(10, pos); }
    }

    $.e = {
        fix: function (e) {
            var e = e || $W.event;
            e.code = e.keyCode || e.which || e.charCode || e.button;
            e.stop = function () { if (isIE) e.cancelBubble = true; else e.stopPropagation(); e.pDefault(); };
            e.pDefault = function () { if (isIE) e.returnValue = false; else e.preventDefault(); };
            if (isIE) { e.target = e.srcElement };
            if (e.target.nodeType == 3) { e.target = e.target.parentNode };
            if (!e.relatedTarget && e.fromElement) { e.relatedTarget = e.fromElement == e.target ? e.toElement : e.fromElement; }
            if (!e.pageX && e.clientX) {
                var b = $DE;
                e.pageX = e.clientX + (b && b.scrollLeft || $DB && $DB.scrollLeft || 0) - (b.clientLeft || 0);
                e.pageY = e.clientY + (b && b.scrollTop || ($DB && $DB.scrollTop) || 0) - (b.clientTop || 0);
            };
            /*if(!e.x) e.x=e.pageX;if(!e.y)e.y=e.pageY;*/
            if (isFF) { e.wheelDelta = -e.detail * 40; } //统一FF下滚轮偏离
            e.t = $(e.target);
            return e;
        },
        setInterval: function (f, t) { var args = [].slice.call(arguments, 2), fn = f; if (args.length > 0) { fn = function () { f.apply(this, args) } }; return $W.setInterval(fn, t); },
        setTimeout: function (f, t) { var args = [].slice.call(arguments, 2), fn = f; if (args.length > 0) { fn = function () { f.apply(this, args) } }; return $W.setTimeout(fn, t); }
    }

    $.g = {
        IMG_PATH: '',
        ROW_S: '\u0001',
        COL_S: '\u0002',
        RESULT_S: '\u0003',
        setImgPath: function (v) {
            return $.g.IMG_PATH = v, $.g;
        },
        getImgPath: function () {
            return $.g.IMG_PATH;
        }
    }

    $.session = {
        key: 'M-SESSION-ID',
        set: function (v) {
            return $.cookie.set($.session.key, v, 1), $.session;
        },
        get: function () {
            return $.cookie.get($.session.key);
        },
        check: function () {
            return $.cookie.get($.session.key) ? true : (MTips.show('登录超时, 请重新登陆!', 'warn'), setTimeout(function () {
                window.location.href = $.g.getImgPath() + 'index.html';
            }, 2000), false);
        }
    }

    $.drag={
        init: function (o, or, minX, maxX, minY, maxY, h, v, xFn, yFn) {
            o.onmousedown = $.drag.start;
            o.ih = h ? false : true;
            o.v = v ? false : true;
            o.rt = or && or != null ? or : o;
            o.s = o.rt.style;
            o.minX = minX || 0;
            o.minY = minY || 0;
            o.maxX = maxX || null;
            o.maxY = maxY || null;
            o.xFn = xFn ? xFn : null;
            o.yFn = yFn ? yFn : null;
            o.p = $.m.p;
            o.rt.onDragStart = o.rt.onDragEnd = o.rt.onDrag = _fn;
            return o;
        },
        start: function (e, o) {
            var o = $.drag.obj = o || this, y = o.p(o.v ? o.s.top : o.s.bottom), x = o.p(o.ih ? o.s.left : o.s.right);
            o.s.display = "block";
            e = e || $W.event;
            o.rt.onDragStart(x, y, e);
            o.lx = e.clientX;
            o.ly = e.clientY;
            if (o.ih) {
                o.iMX = o.lx - x + o.minX; if (o.maxX) { o.xMX = o.iMX + o.maxX - o.minX; }
            } else {
                o.xMX = -o.minX + o.lx + x; if (o.maxX) { o.iMX = -o.maxX + o.lx + x; }
            };
            if (o.v) {
                o.iMY = o.ly - y + o.minY; if (o.maxY) { o.xMY = o.iMY + o.maxY - o.minY; }
            } else {
                o.xMY = -o.minY + o.ly + y; if (o.maxY) { o.iMY = -o.maxY + o.ly + y; }
            };
            $D.onmousemove = $.drag.drag;
            $D.onmouseup = $.drag.end;
            return false;
        },
        drag:function(e){
            var e=$.e.fix(e);e.stop();
            var o = $.drag.obj, ey = e.clientY, ex = e.clientX, mi = $M.min, mx = $M.max, y = o.p(o.v ? o.s.top : o.s.bottom), x = o.p(o.ih ? o.s.left : o.s.right);
            if(o.dragable==false) return;
            ex = o.ih ? mx(ex, o.iMX) : mi(ex, o.xMX);
            if (o.maxX) ex = o.ih ? mi(ex, o.xMX) : mx(ex, o.iMX); ey = o.v ? mx(ey, o.iMY) : mi(ey, o.xMY);
            if (o.maxY) ey = o.v ? mi(ey, o.xMY) : mx(ey, o.iMY);
            var nx = x + ((ex - o.lx) * (o.ih ? 1 : -1)), ny = y + ((ey - o.ly) * (o.v ? 1 : -1));
            if (o.xFn) nx = o.xFn(y); else if (o.yFn) ny = o.yFn(x);
            o.s['left'] = (nx || 0) + 'px';
            o.s[o.v ? 'top' : 'bottom'] = (ny || 0) + 'px';
            o.lx = ex; o.ly = ey; o.rt.onDrag(nx, ny);
            return false;
        },
        end: function () {
            var o = $.drag.obj;
            $D.onmousemove = $D.onmouseup = null;
            o.rt.onDragEnd(o.p(o.s[o.ih ? "left" : "right"]), o.p(o.s[o.v ? "top" : "bottom"]));
            o = null;
        }
    }

    $.cookie = {
        set: function (n, v, h) {
            var sc = n + '=' + encodeURIComponent(v);
            if (h) { var exp = new Date($.time() + h * 36E5); sc += '; expires=' + exp.toGMTString(); };
            document.cookie = sc;
        },
        get: function (n) {
            var oRE = new RegExp('(?:; )?' + n + '=([^;]*);?');
            if (oRE.test($D.cookie)) { return decodeURIComponent(RegExp['$1']); } else { return null; }
        },
        remove: function (n) { this.set(n, null, -9999); },
        clear: function () { $D.cookie = null; }
    }

    $.getType = function () {
        if (arguments.length > 0) {
            var t, o = arguments[0];
            return ((t = typeof (o)) == "object" ? o == null && "null" || Object.prototype.toString.call(o).slice(8, -1) : t).toLowerCase();
        } else {
            var u = navigator.userAgent.toLowerCase(), v = (u.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1];
            if (u.indexOf('applewebkit/') > -1) {
                return 'safari,' + v;
            } else if (!!$W.opera) {
                return 'opera,' + v;
            } else if (u.indexOf('msie') > -1) {
                return 'msie,' + v;
            } else if (u.indexOf('firefox') !== -1) {
                return 'mozilla,' + v;
            } else if (u.indexOf('chrome') !== -1) {
                return 'chrome,' + v;
            }
        }
    }

    $.ls={
        set: function (k, v) { if (this.get(k) !== null) this.remove(k); $LS.setItem(k, v);},
        get: function (k) { var v = $LS.getItem(k); return v === undefined ? null : v;	},
        remove: function (k) { $LS.removeItem(k); },
        clear: function () { $LS.clear(); },
        each: function (fn) { var n = $LS.length, i = 0, fn = fn || _fn, k; for (; i < n; i++) { k = $LS.key(i); if (fn.call(this, k, this.get(k)) === false) { break; }; if ($LS.length < n) { n--; i--; }; }; }  //如果内容被删除，则总长度和索引都同步减少
    }

    $.JSON = new (function () { var _1 = {}.hasOwnProperty ? true : false; var m = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", "\"": "\\\"", "\\": "\\\\" }; var _5 = function (s) { if (/["\\\x00-\x1f]/.test(s)) { return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { var c = m[b]; if (c) { return c; } c = b.charCodeAt(); return "\\u00" + $M.floor(c / 16).toString(16) + (c % 16).toString(16); }) + "\""; } return "\"" + s + "\""; }; var _a = function (o) { var a = ["["], b, i, l = o.length, v; for (i = 0; i < l; i += 1) { v = o[i]; switch (typeof v) { case "undefined": case "function": case "unknown": break; default: if (b) { a.push(","); } a.push(v === null ? "null" : $.JSON.encode(v)); b = true; } } a.push("]"); return a.join(""); }; this.encode = function (o) { if (typeof o == "undefined" || o === null) { return "null"; } else { if (o instanceof Array) { return _a(o); } else { if (o instanceof Date) { return o.date2Str(); } else { if (typeof o == "string") { return _5(o); } else { if (typeof o == "number") { return isFinite(o) ? String(o) : "null"; } else { if (typeof o == "boolean") { return String(o); } else { var a = ["{"], b, i, v; for (i in o) { if (!_1 || o.hasOwnProperty(i)) { v = o[i]; switch (typeof v) { case "undefined": case "function": case "unknown": break; default: if (b) { a.push(","); } a.push(this.encode(i), ":", v === null ? "null" : this.encode(v)); b = true; } } } a.push("}"); return a.join(""); } } } } } } }; this.decode = function (_18) { return eval("(" + _18 + ")"); }; })();
    $.onReady = function (f) { if (!isIE) { _x.evt.call($D, 'DOMContentLoaded', f, false); } else { var t = setInterval(function () { try { $DB.doScroll('left'); clearInterval(t); setTimeout(f, 48); } catch (e) { } }, 48) }; };
    $.noSel=function(){if($D.selection){if($D.selection.empty)$D.selection.empty();else{$D.selection = null;}}else if(getSelection){try{getSelection().removeAllRanges()}catch(e){}}};
    $.time = function () { return +(new Date) || Date.now;};
    $.rnd = function (a, b) { return $M.round($M.random($.time) * (b - a)) + a;};
    $.nCount = function () { var me = this; me.i = -1; me.getN = function () { me.i++; return me.i; }; me.setN = function (n) { me.i = n; };};
    $.wh = function () {
        var _w, _h = 0;
        if (typeof ($W.innerWidth) == 'number') {
            _w = $W.innerWidth;
            _h = $W.innerHeight;
        } else if ($DE && ($DE.clientWidth || $DE.clientHeight)) {
            _w = $DE.clientWidth;
            _h = $DE.clientHeight;
        } else if ($DB && ($DB.clientWidth || $DB.clientHeight)) {
            _w = $DB.clientWidth;
            _h = $DB.clientHeight;
        }

        return [_w / 2 + ($DE.scrollLeft || $DB.scrollLeft), _h / 2 + ($DE.scrollTop || $DB.scrollTop)];
    }

    $.box = function (a) {
        var a = a.split(',');
        return (a[0].length ? 'left:' + a[0] + 'px;' : '') + (a[1].length ? 'top:' + a[1] + 'px;' : '') + (a[2].length ? 'width:' + a[2] + 'px;' : '') + (a[3].length ? 'height:' + a[3] + 'px;' : '');
    }

    $.key = {
        stat: [],
        kd: function (e) {
            var e = $.e.fix(e);
            $.key.stat[e.code] = 1;
        },
        ku: function (e) {
            var e = $.e.fix(e);
            $.key.stat[e.code] = 0;
        },
        bind: function (o) {
            var me = this;
            me.o = o || $D;
            me.o.revt('keydown', $.key.kd);
            me.o.revt('keyup', $.key.ku);
            me.o.evt('keydown', $.key.kd);
            me.o.evt('keyup', $.key.ku);
            me.addKey = function (aKey, key, pressStat, cbFn) {
                var _f = function (e) {
                    var e = $.e.fix(e);
                    if (e.shiftKey) { $.key.stat[16] = 1; } else { $.key.stat[16] = 0; }
                    if (e.ctrlKey) { $.key.stat[17] = 1; } else { $.key.stat[17] = 0; }
                    if (e.altKey) { $.key.stat[18] = 1; } else { $.key.stat[18] = 0; }
                    if (e.code != key) { return; }
                    var _n = 1;
                    for (var i = 0; i < aKey.length; i++) { if (aKey[i] == key) { continue; }; _n = _n * $.key.stat[aKey[i]]; };
                    if (_n == 1) { cbFn(); }
                }
                me.o.evt(pressStat ? 'keydown' : 'keyup', _f);
            }

            return me;
        }
    }

    $.aCache={
        num:0,size:0, hash:[],
        get: function (s) { var _o = this.hash[s]; if (!_o||(_o.t+_o.e)<$.time()) { return null; }; return _o.d; },
        set:function(s,d,t){ var h=this.hash; if (!h[s]) { return -1; }; h[s].d = d; h[s].t = t; },
        push:function(s,d,e){ this.hash[s] = { d: d, t: $.time(), e: e * 1000 || 10000 }; this.size+=d.length; this.num++; },
        diff: function (s) { var h = this.hash; if (!h[s]) { return -1; }; var b = $.time() - h[s].t; if (b > h[s].e) { this.size -= h[s].d.length; this.num--; h[s] = null; return -1; }; return b;}
    }

    if (isIE) {

        try {
            $D.execCommand('BackgroundImageCache', false, true);
        } catch (e) {

        }

        if (+$('').split(',')[1] < 8) {
            var UserData = function (file_name) {
                if (!file_name) { file_name = "user_data_default"; }
                var dom = $D.createElement('input');
                dom.type = "hidden";
                dom.addBehavior("#default#userData");
                $DB.appendChild(dom);
                dom.save(file_name);
                this.file_name = file_name;
                this.dom = dom;
                return this;
            }

            UserData.prototype = {
                set: function (k, v) { this.dom.setAttribute(k, v); this.dom.save(this.file_name); },
                get: function (k) { this.dom.load(this.file_name); return this.dom.getAttribute(k); },
                remove: function (k) { this.dom.removeAttribute(k); this.dom.save(this.file_name); },
                clear: function () { this.dom.load(this.file_name); var now = new Date(); now = new Date(now.getTime() - 1); this.dom.expires = now.toUTCString(); this.dom.save(this.file_name); }
            };

            $.ls = UserData("Fily");
        }
    } else {
        HTMLElement.prototype.insertAdjacentElement = function (w, p) {
            switch (w) {
                case 'beforeBegin': return $(this.parentNode.insertBefore(p, this)); break;
                case 'afterBegin': return $(this.insertBefore(p, this.firstChild)); break;
                case 'beforeEnd': return $(this.appendChild(p)); break;
                case 'afterEnd': if (this.nextSibling) { return $(this.parentNode.insertBefore(p, this.nextSibling)); } else { return $(this.parentNode.appendChild(p)); }; break;
            }
        }
    }

    if (window.HTMLElement) {
        HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) { var r = this.ownerDocument.createRange(); r.setStartBefore(this); var df = r.createContextualFragment(sHTML); this.parentNode.replaceChild(df, this); return sHTML; });
        HTMLElement.prototype.__defineGetter__("outerHTML", function () {
            var attr, attrs = this.attributes, str = "<" + this.tagName.toLowerCase();
            for (var i = 0; i < attrs.length; i++) { attr = attrs[i]; if (attr.specified) { str += " " + attr.name + '="' + attr.value + '"'; }; }
            if (!this.canHaveChildren) { return str + ">"; }
            return str + ">" + this.innerHTML + "</" + this.tagName.toLowerCase() + ">";
        });
        HTMLElement.prototype.__defineGetter__("canHaveChildren", function () { switch (this.tagName.toLowerCase()) { case "area": case "base": case "basefont": case "col": case "frame": case "hr": case "img": case "br": case "input": case "isindex": case "link": case "meta": case "param": return false; }; return true; });
    }

    $.ext(Number.prototype, _number);
    $.ext(String.prototype, _s);
    $.ext(Array.prototype, _a);
    $.ext(Date.prototype, _d);
    $.ext(Function.prototype, _f);
    $.ext($, _load);
    $.ext($W, _w);
    $.ext($D, _x);
    $.ext($DB, _x);

    return $;
})(window);